package com.gzq.learn.springbootdemo.domain.dao.jpa;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.gzq.learn.springbootdemo.domain.UserDTO;

/**
 * 
 * @author GZQ
 *
 */
@Repository
public interface UserRepository extends JpaRepository<UserDTO, Long> {
    
    //通过指定user_name(userName)作为查询条件查找User的数据
    UserDTO findByUserName(String userName);

    // 通过Or关键字将user_name(userName)和email作为or的查询条件来查询User数据
    UserDTO findByUserNameOrEmail(String userName, String email);
    
    //自定义sql语句
    @Transactional(timeout=30)
    @Modifying //如果涉及到删除和修改，需要加上@Modifying
    @Query("update user u set u.userName = ?1 where u.id = ?2")
    int modifyByIdAndUserId(String  userName, Long id);
    
    
}
